import 'package:flutter/material.dart';

class MyRadio extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyRadioState();
}

class MyRadioState extends State {
  String sex = '男';
  bool flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('MyRadio')),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Text('女:'),
              Radio(
                value: '女',
                groupValue: this.sex,
                onChanged: (value) {
                  this.setState(() {
                    this.sex = value;
                  });
                  print(this.sex);
                },
              ),
              SizedBox(width: 100),
              Text('男:'),
              Radio(
                value: '男',
                groupValue: this.sex,
                onChanged: (value) {
                  this.setState(() {
                    this.sex = value;
                  });
                  print(this.sex);
                },
              ),
            ],
          ),
          Text(this.sex,
              style: TextStyle(
                fontSize: 40,
                color: Colors.red,
              )),
          SizedBox(height: 50),
          RadioListTile(
            title: Text('男'),
            subtitle: Text('性别'),
            secondary: Icon(Icons.people_alt),
            value: '男',
            groupValue: this.sex,
            onChanged: (value) {
              this.setState(() {
                this.sex = value;
              });
            },
            selected: this.sex == '男',
          ),
          RadioListTile(
            title: Text('女'),
            subtitle: Text('性别'),
            secondary: Icon(Icons.people_alt),
            value: '女',
            groupValue: this.sex,
            onChanged: (value) {
              this.setState(() {
                this.sex = value;
              });
            },
            selected: this.sex == '女',
          ),
          SizedBox(height: 20),
          Switch(
            value: this.sex == '女' ? true : false,
            onChanged: (bool value) {
              this.setState(() {
                this.sex = value ? '女' : '男';
              });
            },
          )
        ],
      ),
    );
  }
}
